/*
 * WapAjaxAuthInterceptor.java
 * Copyright 2021 Qunhe Tech, all rights reserved.
 * Qunhe PROPRIETARY/CONFIDENTIAL, any form of usage is subject to approval.
 */
package top.bbman.boot.auth.interceptor;


import com.alibaba.fastjson.JSON;
import top.bbman.boot.logger.LogConstant;
import top.bbman.boot.repository.enums.PeaCodeEnum;
import top.bbman.boot.repository.vo.PeaOut;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


public class WapAjaxAuthInterceptor extends WapAuthenticationInterceptor {


	@Override
	protected void doNoLogin(HttpServletRequest request, HttpServletResponse response) {
		LogConstant.bbManAuth.info("Ajax request auth failed, " + request.getRequestURI());

		try {
			response.setContentType("application/json; charset=utf-8");
			response.getWriter().print(JSON.toJSONString(PeaOut.build(PeaCodeEnum.NO_LOGIN)));
		} catch (IOException e) {
			e.printStackTrace();
			LogConstant.bbManAuth.warn("[Login Ajax Check] exception", e);
		}
	}

	@Override
	protected void doNoPermission(HttpServletRequest request, HttpServletResponse response) throws Exception {
		LogConstant.bbManAuth.info("Ajax request auth failed, " + request.getRequestURI());

		try {
			response.setContentType("application/json; charset=utf-8");
			response.getWriter().print(JSON.toJSONString(PeaOut.build(PeaCodeEnum.NO_PERMISSION)));
		} catch (IOException e) {
			e.printStackTrace();
			LogConstant.bbManAuth.warn("[Login Ajax Check] exception", e);
		}
	}
}
